package fr.neticar.webremoteclient.server.application;

import java.awt.Component;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;

import fr.neticar.webremoteclient.client.ImagePropertyBean;
import fr.neticar.webremoteclient.client.exception.WRCException;
import fr.neticar.webremoteclient.server.ImageContentBean;
import fr.neticar.webremoteclient.server.ImageManager;
import fr.neticar.webremoteclient.server.vncviewer.VncCanvas;
import fr.neticar.webremoteclient.server.vncviewer.VncViewer;

public class VNCClient implements IRemoteClient {

	private VncViewer vnc;
	
	private ImageManager imageManager;

	public VNCClient(String host, String port, String password)
			throws WRCException {
		imageManager = new ImageManager();
		vnc = new VncViewer(host, port, password,imageManager);

	}
	
	@Override
	public ImagePropertyBean getNextImageProperty() {
		
		return imageManager.getFirstBean();
	}

	@Override
	public int getScreenHeight() {
			return (int) vnc.getDeskTopSize().getHeight();
	}

	@Override
	public int getScreenWidth() {

		return (int) vnc.getDeskTopSize().getWidth();

	}

	@Override
	public void sendKeyEvent(KeyEvent ke) {
		VncCanvas vncCanvas = vnc.getVncCanvas();
		vncCanvas.processLocalKeyEvent(ke);

	}

	@Override
	public void sendMouseEvent(MouseEvent e,boolean b) {
		VncCanvas vncCanvas = vnc.getVncCanvas();
		vncCanvas.processLocalMouseEvent(e, b);

	}

//	@Override
//	public void start() {
//		vnc.
//
//	}

	@Override
	public void stop() {
		vnc.disconnect();

	}
	@Override
	public Component getEventSourceComponent() {
		
		return vnc.getVncCanvas();
	}
	
	@Override
	public boolean containsNewImage() {
		
		return imageManager.containsImage();
	}
	
	@Override
	public ImageContentBean getNextImage(String id) {
		return imageManager.getImage(id);
	}

}
